//
//  CategoryManager.m
//  SAYAKA_Table
//
//  Created by numanuma08 on 2013/07/20.
//  Copyright (c) 2013年 勘米良. All rights reserved.
//

#import "CategoryManager.h"
#import "NSArray+mapUsingBlock.h"
#import "Category.h"


@implementation CategoryManager
static NSString* const kENTITY = @"Category";

+ (NSString*)entity
{
    return kENTITY;
}

+ (NSArray*)allRecord:(NSManagedObjectContext*)managedobjectContext
{
    NSEntityDescription* entity = [NSEntityDescription entityForName:@"Category" inManagedObjectContext:managedobjectContext];
    
    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc]init];
    fetchRequest.entity = entity;
    
    NSSortDescriptor* sortDescription = [[NSSortDescriptor alloc]initWithKey:@"order_number" ascending:YES];
    fetchRequest.sortDescriptors = @[sortDescription];
    
    NSArray* fetchResult = [managedobjectContext executeFetchRequest:fetchRequest error:nil];
    NSArray* categoris = [fetchResult mapUsingArray:^(id object){ return (Category*)object;}];

    return categoris;
}

@end
